package redisenum

import (
	"yunj/pkg/yunj/app/enum/redisenum"
	"yunj/pkg/yunj/core/enum"
)

type Group struct {
	redisenum.Group
}

const (
	// 后台仪表台缓存分组
	GROUP_DASHBOARD int = iota

	// GROUP_TEST
)

// 所有常量属性
func (rg *Group) AllConstAttrs() map[int]map[string]any {
	return map[int]map[string]any{
		GROUP_DASHBOARD: map[string]interface{}{
			"desc":            "后台仪表台缓存分组",
			"parent":          "",
			"keyBaseInstance": KeyEnum, // 用于获取keys的枚举实例
			"keys": []string{
				KEY_HOUR_REQUEST_PV_BY_DATE,
				KEY_HOUR_REQUEST_UV_BY_DATE,
				KEY_HOUR_LOGIN_UV_BY_DATE,
				KEY_TODAY_PROV_REQUEST_PV,
				KEY_TODAY_PROV_REQUEST_UV,
			},
		},
	}
}

// 存储已经创建的实例
var groupInstanceCache = make(map[int]*Group)

// 根据value获取枚举
func GroupByValue(value int) *Group {
	if instance, exists := groupInstanceCache[value]; exists {
		return instance
	}
	e := &Group{Group: redisenum.Group{}}
	e.Group.GroupInstance = e
	enum.SetEnumInstance(&e.Enum, e, value)
	groupInstanceCache[value] = e
	return e
}

var GroupEnum *Group = func() *Group {
	e := &Group{Group: redisenum.Group{}}
	e.Group.GroupInstance = e
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
